;;; helm.cfg.el --- Summary
;;; Commentary:
;;; configuration for helm
;;; Code:

(require 'package.cfg)

;; Emacs incremental completion and selection narrowing framework
;; https://github.com/emacs-helm/helm
(package-install-if-absent 'helm)

(defun my-add-to-helm-boring-file-regexp-list (ext-list)
  "Add extra extensions in EXT-LIST to helm-boring-file-regexp-list."
  (mapc
   (lambda (an-element)
     (when
         (not (cl-position an-element helm-boring-file-regexp-list :test 'string=))
       (add-to-list 'helm-boring-file-regexp-list an-element)))
   ext-list))

(when
    (executable-find "ag")
  (progn
    (package-install-if-absent 'helm-ag)
    (use-package helm-ag)))

(use-package helm-config
  :init
  (progn
    (helm-mode 1)
    (helm-adaptive-mode 1)
    (helm-push-mark-mode 1)
    (my-add-to-helm-boring-file-regexp-list '("\\.elc$" "\\.py[cod]$"))
    (custom-set-variables
     '(helm-command-prefix-key "C-c h")))
  :config
  (define-key shell-mode-map (kbd "C-c C-l") 'helm-comint-input-ring)
  (define-key minibuffer-local-map (kbd "C-c C-l") 'helm-minibuffer-history)
  (define-key helm-command-map (kbd "o" ) 'helm-occur)
  (define-key helm-command-map (kbd "M-s o") nil)
  :diminish helm-mode
  :bind
  (("M-x" . helm-M-x)
   ("M-y" . helm-show-kill-ring) ;; replace yank-pop
   ("C-h SPC" . helm-all-mark-rings)
   ("C-x C-f" . helm-find-files)
   ("C-x C-b" . helm-buffers-list)
   ("C-x b" . helm-mini)
   ("M-/" . helm-dabbrev)))

(use-package helm
  :config
  (use-package helm-config)
  (setq helm-move-to-line-cycle-in-source t
        helm-ff-file-name-history-use-recentf t
        helm-ff-newfile-prompt-p nil
        helm-ff-skip-boring-files t
        helm-ff-ido-style-backspace 'always
        helm-ff-auto-update-initial-value t
        helm-ff--auto-update-state t))

(package-install-if-absent 'helm-c-yasnippet)
(use-package helm-c-yasnippet
  :config
  (setq helm-yas-space-match-any-greedy t
        helm-yas-display-msg-after-complete nil
        helm-yas-display-key-on-candidate t)
  :bind
  ("C-c y" . helm-yas-complete))

(provide 'helm.cfg)
;;; helm.cfg.el ends here
